package ytmc.setup;

import org.apache.commons.configuration.XMLConfiguration;


/**
 * Utilities for configuration managing
 *
 * @author Kicok
 */
public class ConfigUtils
{
    public static <T extends Enum<T>> T getEnum( XMLConfiguration config, String propertyName, T defaultValue )
    {
        try
        {
            String valueName = config.getString( propertyName );
            return (T)Enum.valueOf( defaultValue.getClass(), valueName );
        }
        catch( Exception e )
        {
            return defaultValue;
        }
    }

    public static void removeProperty( XMLConfiguration config, String propertyName )
    {
        ( (XMLConfiguration)config ).clearTree( propertyName );
    }
}